//先计算这些年总的天数，判断是不是闰年366天，平年365天
var year = 2019;
var month = 5;
var day = 0;


document.querySelector("#nian").innerHTML = (year);
document.querySelector("#yue").innerHTML = (month);


function runNian(y){
    if(y % 400 ===0 || y % 4 ===0 && y % 100 !==0){
        return true;
    }else {
        return false;
    }
}

for (var n=1980;n<year;n++){
    if (runNian(n)){
        day += 366;
    }else {
        day += 365;
    }
}
console.log(day);

//然后计算2019年1-4月份的天数
for (var m=1;m<month;m++){
    switch (m){
        case 1:
            day +=31;
            break;
        case 2:
            if (runNian(year)){
                day +=29;
            }else {
                day +=28;
            }
            break;
        case 3:
            day +=31;
            break;
        case 4:
            day +=30;
            break;
        case 5:
            day +=31;
            break;
        case 6:
            day +=30;
            break;
        case 7:
            day +=31;
            break;
        case 8:
            day +=31;
            break;
        case 9:
            day +=30;
            break;
        case 10:
            day +=31;
            break;
        case 11:
            day +=30;
            break;
        case 12:
            day +=31;
            break;
    }
}
console.log(day);
//再然后要计算出本月的起始位置
//要加上1920年01月01日的起始位置2
day +=2;
console.log(day);




var start = day %7;
console.log(start);

if (start == 0){
    start +=7;
}


//计算的当月的天数
var days = 0;
switch (month){
    case 1:
        days +=31;
        break;
    case 2:
        if (runNian(year)){
            days +=29;
        }else {
            days +=28;
        }
        break;
    case 3:
        days +=31;
        break;
    case 4:
        days +=30;
        break;
    case 5:
        days +=31;
        break;
    case 6:
        days +=30;
        break;
    case 7:
        days +=31;
        break;
    case 8:
        days +=31;
        break;
    case 9:
        days +=30;
        break;
    case 10:
        days +=31;
        break;
    case 11:
        days +=30;
        break;
    case 12:
        days +=31;
        break;
}
console.log(days);


 var lastDay = 0;
//计算上一个月的天数



if (month = 1){
    lastDay +=31;
}else {
    switch (month-1){
        case 1:
            lastDay +=31;
            break;
        case 2:
            if (runNian(year)){
                lastDay +=29;
            }else {
                lastDay +=28;
            }
            break;
        case 3:
            lastDay +=31;
            break;
        case 4:
            lastDay +=30;
            break;
        case 5:
            lastDay +=31;
            break;
        case 6:
            lastDay +=30;
            break;
        case 7:
            lastDay +=31;
            break;
        case 8:
            lastDay +=31;
            break;
        case 9:
            lastDay +=30;
            break;
        case 10:
            lastDay +=31;
            break;
        case 11:
            lastDay +=30;
            break;
        case 12:
            lastDay +=31;
            break;
    }
}

console.log(lastDay);

//日历总共有42个
var num = 42;
var nextDay = num -start -days;


////再然后要计算出本月的起始位置
////要加上1920年01月01日的起始位置2
//day +=2;
//console.log(day);
//var start = day %7;
//console.log(start);

var thisdate=new Date().getDate();

var date = document.querySelector("#date1");

//用三个for循环写出当前2019年5月份的格式
for (var s=lastDay-start+1;s<=lastDay;s++){
    date.innerHTML += "<span class='h'>"+s+"</span>"
}
for (var p=1;p<=days;p++){
    if(p === thisdate){
        date.innerHTML +="<span class='today'>"+p+"</span>"
    }else {
        date.innerHTML += "<span>"+p+"</span>"
    }
}
for (var t=1;t<=nextDay;t++){
    date.innerHTML += "<span class='h'>"+t+"</span>"
}
//最后返回上面计算上个月的天数和当月的天数
//计算上个月的作用是：上个月有多少天-余的空格数+1就是从第几天开始然后
//从这个月有多少天结束

